package com.ysd.twocrm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysd.twocrm.entity.Student;
import com.ysd.twocrm.mapper.StudentMapper;
import com.ysd.twocrm.service.StudentService;
import com.ysd.twocrm.utils.LayuiUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    /*
     * 多条件分页查询学生
     * */
    @Override
    public LayuiUtils<Student> layuiutis(Integer page, Student s) {
        LayuiUtils<Student> ls=new LayuiUtils<>();//工具类

        Page<Student> page1=new Page<>(page,10);//分页
        //条件构造器
        QueryWrapper<Student> queryWrapper=new QueryWrapper<Student>();
        //开始+条件
        if(s.getStudentName()!=null){
            queryWrapper.like("student.studentName",s.getStudentName());//模糊查询姓名
        }
        if(s.getStuClassId()!=null){
            queryWrapper.eq("student.stuClassId",s.getStuClassId());
        }

        Page<Student> allStudent = studentMapper.findAllStudent(page1, queryWrapper);
        ls.setData(allStudent.getRecords());//查询全部数据
        ls.setCount(allStudent.getTotal());//总条数
        return ls;
    }

    @Override
    public Integer addStudent(Student s) {
        return studentMapper.insert(s);
    }

    @Override
    public Integer exitStudent(Student s) {
        return studentMapper.updateById(s);
    }

    @Override
    public Integer delStudent(Integer studentId) {
        return studentMapper.deleteById(studentId);
    }
}
